/**
 * 2009-10-27 下午04:11:01 
 * esignature
 * com.smc.action.user
 * UserTestAction
 */
package com.smc.action.user;

import java.sql.Date;

import com.opensymphony.xwork2.ActionSupport;
import com.smc.common.constants.AuthorityConstant;
import com.smc.common.constants.ResourceConstant;
import com.smc.common.constants.RoleConstant;
import com.smc.domain.model.Authentication;
import com.smc.domain.model.Hospital;
import com.smc.domain.model.User;
import com.smc.security.util.CoderUtil;
import com.smc.server.AuthenticationService;
import com.smc.server.UserService;

/**
 * @author chenheng
 * @version 0.0.1
 */
public class UserTestAction extends ActionSupport {
	
	private UserService userService ;
	private AuthenticationService authenticationService ;
	
	private User user ;
	
	private static final long serialVersionUID = 6562674186886615330L;

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	public AuthenticationService getAuthenticationService() {
		return authenticationService;
	}

	public void setAuthenticationService(AuthenticationService authenticationService) {
		this.authenticationService = authenticationService;
	}

	public String addTestUser() throws Throwable {
		
		user = new User();
		Hospital h = new Hospital();
		
//		/*
//		 * 管理员角色用户admin,密码也为admin,他具有所有角色、所有资源，所有权限的全部权值。
//		 */
//		//h.setUuid("402880e524999f80012499a0bdbc0002");
//		//user.setHospital(h);
//		user.setIntroduction("I am a administor");
//		user.setUsername("admin");
//		user.setPassword(CoderUtil.byte2hex(CoderUtil.encryptMD5(("admin" + "admin").getBytes())));
		
//		/**
//		 * 操作角色用户operator,密码也为operator，他具有操作员角色，对文档有fetch,save的权限，对医院有fetch权限，对用户有fetch权限
//		 */
//		//h.setUuid("402880e524999f80012499a0bdbc0002");
//		//user.setHospital(h);
//		user.setIntroduction("I am a opeator");
//		user.setUsername("operator");
//		user.setPassword(CoderUtil.byte2hex(CoderUtil.encryptMD5(("operator" + "operator").getBytes())));
		
//		/**
//		 * 医生角色用户doctor，密码也为doctor，他具有医生角色,对文档具有fetch,sign的权限
//		 */
//		h.setUuid("402880e524999f80012499a0bdbc0002");
//		user.setHospital(h);
//		user.setIntroduction("I am a doctor");
//		user.setUsername("doctor");
//		user.setPassword(CoderUtil.byte2hex(CoderUtil.encryptMD5(("doctor" + "doctor").getBytes())));
		/**
		 * 医院角色用户hospital,密码也为hospital，他具有医院角色.
		 */
		h.setUuid("402880e524999f80012499a0bdbc0002");
		user.setHospital(h);
		user.setIntroduction("I am a hospital");
		user.setUsername("hospital");
		user.setPassword(CoderUtil.byte2hex(CoderUtil.encryptMD5(("hospital" + "hospital").getBytes())));
		
		user.setBirthday(Date.valueOf("1987-06-12"));
		user.setCellphone("021-88881234");
		user.setEmail("neatchenheng@gmail.com");
		user.setFirstName("secure medical chat");
		user.setFamilyTel("021-52243973");
		user.setFax("021-88881234");
		user.setHomeAddress("210# yaohua road,shanghai,china");
		user.setHospitalAddress("100# shangang road,shanghai,china");
		user.setHospitalTel("021-52242592");
		user.setLastName("e-signature");
		user.setOfficeAddress("100# shangang road,shanghai,china");
		user.setOfficeTel("021-52242592");
		user.setPersonalPicture("header.png");
		user.setRegisterTime(Date.valueOf("2009-11-4"));
		user.setUuid(null);
		
		userService.save_HO_US_SA_user(user);	
		return SUCCESS ;
	}
	
	public String grantUserAuth() {
		Authentication auth = new Authentication();
		User user = new User();
		
//		/**
//		 * admin的权限
//		 */
//		user.setUuid("402881e424cd9e140124cdd623ca0005");
//		auth.setAuthority(AuthorityConstant.AUTH_FETCH + AuthorityConstant.AUTH_REMOVE + AuthorityConstant.AUTH_SAVE + AuthorityConstant.AUTH_SIGN + AuthorityConstant.AUTH_UPDATE);
//		auth.setResource(ResourceConstant.RES_DOCUMENT + ResourceConstant.RES_AUTHENTICATION + ResourceConstant.RES_HOSPITAL + ResourceConstant.RES_MESSAGE + ResourceConstant.RES_NEWS + ResourceConstant.RES_USER );
//		auth.setRole(RoleConstant.ROLE_OPERATE + RoleConstant.ROLE_ADMIN + RoleConstant.ROLE_HOSPITAL + RoleConstant.ROLE_USER);
		
//		/**
//		 * operator的权限
//		 */
//		user.setUuid("402881e424cd9e140124cddde0fd0006");
//		auth.setAuthority(AuthorityConstant.AUTH_FETCH + AuthorityConstant.AUTH_SAVE );
//		auth.setResource(ResourceConstant.RES_DOCUMENT );
//		auth.setRole(RoleConstant.ROLE_OPERATE);
//		auth.setAuthority(AuthorityConstant.AUTH_FETCH  );
//		auth.setResource(ResourceConstant.RES_HOSPITAL );
//		auth.setRole(RoleConstant.ROLE_OPERATE);
//		auth.setAuthority(AuthorityConstant.AUTH_FETCH  );
//		auth.setResource(ResourceConstant.RES_USER);
//		auth.setRole(RoleConstant.ROLE_OPERATE);
		
		
//		/**
//		 * doctor的权限
//		 */
//		user.setUuid("402881e424cd9e140124cde6f5930007");
//		auth.setAuthority(AuthorityConstant.AUTH_FETCH + AuthorityConstant.AUTH_SIGN + AuthorityConstant.AUTH_UPDATE );
//		auth.setResource(ResourceConstant.RES_DOCUMENT );
//		auth.setRole(RoleConstant.ROLE_USER);
//		
//		
		/**
		 * hospital的权限
		 */
		user.setUuid("402881e424e38b130124e3a1f5b00001");
		auth.setAuthority(AuthorityConstant.AUTH_FETCH + AuthorityConstant.AUTH_COUNT);
		auth.setResource(ResourceConstant.RES_DOCUMENT);
		auth.setRole(RoleConstant.ROLE_HOSPITAL);
		auth.setUser(user);
		auth.setUuid(null);
		authenticationService.save_AD_AU_SA_authentication(auth);
		return SUCCESS ;
	}
	
}
